package com.onnext.androidsdk.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import com.onnext.androidsdk.R;

public class BaseActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private FrameLayout base_container;
    private TextView title;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_base);
        toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("");
        title = findViewById(R.id.title);
        base_container = findViewById(R.id.base_container);

    }

    @Override
    public void setContentView(View view) {
         base_container.addView(view,new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    @Override
    public void setContentView(int layoutResID) {
         base_container.addView(LayoutInflater.from(this).inflate(layoutResID, null),
                 new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    }

    @Override
    public void setContentView(View view, ViewGroup.LayoutParams params) {
        base_container.addView(view, params);
    }

    public void setTitle(String str) {
        title.setText(str);
    }

    public void showBack() {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
}
